/*========================== master.do ========================================*
Build all datasets and run all analysis. User must set two paths below (lines 16-17):
	+ set cd to wherever the Pandemic_Innovation_Share location (inclusive)
	+ set GIT macro to code location (inclusive); users have two options:
		- this could be cloned repo location
		- `c(pwd)'/code/
		
For the Build Data portion of the workflow, order matters! Follow the order given.
*=============================================================================*/

clear
set more off

*============== User Edit Here ===================*

cd 	"C:/Users/Chris.Severen/Dropbox/Data_Projects/Pandemic_Innovation_Share/"
global GIT	"C:/Users/Chris.Severen/Dropbox/Data_Projects/Pandemic_Innovation_Share/git"

*================= Processing + Analysis ================*
* Execute these files in order (even all at once) *

global RES 	"`c(pwd)'/results/"
local 	D = c(current_date)

** Build Data **

do		"$GIT/code/build/make_cusp_cities.do"				 // 43 cities in Markel
do		"$GIT/code/build/make_cusp_cities_patcats.do"		 //  + Makes wide data based on 1-digit CPC patent categories

do		"$GIT/code/build/make_cusp_cities_cls.do"			// ~500 cities in Clay, Lewis, Severnini, will keep 7 found on pandemic archive
do		"$GIT/code/build/make_cusp_cities_cls_patcats.do" 	//  + Makes wide data based on 1-digit CPC patent categories

do		"$GIT/code/build/make_cusp_cities_patcats_long1d.do" // Makes long data based on 1-digit CPC patent categories for NPI and CLS cities
do		"$GIT/code/build/make_cusp_cities_patcats_long3d.do" // Makes long data based on 3-digit CPC patent categories for NPI and CLS cities

do		"$GIT/code/build/make_cusp_breakthroughs.do" 	// Makes file on breakthrough patents for NPI and CLS cities

do		"$GIT/code/build/make_npis.do"		// Read in NPI data from Markel et al + Populations
do		"$GIT/code/build/make_pop.do"		// Read in populations for patenting rate denominators
do		"$GIT/code/build/make_clsdata.do" 	// Read in CLS data + NPIs (also calculates deprecated measure of excess mortality)
do		"$GIT/code/build/make_controls.do"  // Read in controls and population measure for controls
do		"$GIT/code/build/make_migration.do" // Read in data and measures related to migration
do		"$GIT/code/build/make_invage.do" 	// Read in data about inventor age
do		"$GIT/code/build/make_prohibition.do" 	// Read in data about prohibition

do		"$GIT/code/build/prep_cities_npispatents.do"		// Cleaning/Merging
do		"$GIT/code/build/prep_cities_npispatents_cats.do"	// ...
do		"$GIT/code/build/prep_cities_clspatents.do"			// ...
do		"$GIT/code/build/prep_cities_clspatents_cats.do" 	// ...

do		"$GIT/code/build/combine_cities_expanded.do" 		// Combination of npispatents & clspatents, with seven extra cities NPIs
do		"$GIT/code/build/combine_cities_expanded_cats.do" 	// Combination of npispatents & clspatents, with seven extra cities NPIs
do		"$GIT/code/build/combine_cities_expanded_cats_long.do" 	// Uses results of /combine_cities_expanded to build out long data
do		"$GIT/code/build/combine_cities_expanded_breakthrough.do" 	// Uses results of /combine_cities_expanded to build out breakthrough data
do		"$GIT/code/build/combine_cities_expanded_ageyoungold.do" 	// Uses results of /combine_cities_expanded to build out patent data by age


** Analysis - NPI Results + Pictures in paper **
do		"$GIT/code/analysis/graphs_by_npi_group.do"	
do		"$GIT/code/analysis/graphs_histogram.do"

do		"$GIT/code/analysis/cities_npis_main.do" 		
do		"$GIT/code/analysis/cities_npis_expanded.do"		
do		"$GIT/code/analysis/cities_npis_expanded_cats.do"

do		"$GIT/code/analysis/cities_npis_eventstudy.do"
do		"$GIT/code/analysis/cities_npis_cutoffs.do"
do		"$GIT/code/analysis/cities_npis_jackknife.do"
do		"$GIT/code/analysis/cities_npis_breakthr_migr_age.do"
do		"$GIT/code/analysis/cities_npis_prohibition.do"

** Analysis - Results only for editor comments **
do		"$GIT/code/analysis/analyze_Lilley_et_al_data.do"
do		"$GIT/code/analysis/cities_npis_mayors.do"


